package com.zjj.learn.javaplus.pkg07.demo701;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class TCPClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 9699);

        OutputStream os = socket.getOutputStream();
        os.write("您好，周末约吗？".getBytes(StandardCharsets.UTF_8));

        //获取字节输入流
        InputStream is = socket.getInputStream();
        //创建一个字节数组，用于存储服务端返回的数据
        byte[] buf = new byte[1024];
        int len = is.read(buf);
        System.out.println("返回的数据：" + new String(buf, 0, len));
    }
}
